package fr.epsi.studentsmaps;

import fr.epsi.ressources.EpsiStudents;
import fr.epsi.services.LocalisationService;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	
	
	private EditText login;
	private EditText pass;
	private ImageView connect;
	
	private EpsiStudents epsiStudents;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		login = (EditText) findViewById(R.id.email);
		pass = (EditText) findViewById(R.id.password);
		connect = (ImageView) findViewById(R.id.connect);
		connect.setOnClickListener(this);
		
		
		epsiStudents = new EpsiStudents();

		
	}
	
	@Override
	protected void onResume ()
	{	 
		 super.onResume();

	}
	

	
	@Override
	protected void onDestroy ()
	{
		super.onDestroy();
	}

	/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}*/

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		boolean tmp=false;
		if(v == connect)
		{
			
			String smail,spass;
			
			smail = login.getText().toString();
			spass = pass.getText().toString();
			
			
			Log.i("Ma",smail);
			Log.i("Ma",spass);
			
			for(int i = 0; i < epsiStudents.list.size(); i++)
			{
				if(epsiStudents.list.get(i).getEmail().equals(smail) && epsiStudents.list.get(i).getPassword().equals(spass))
				{
					tmp=true;
					Intent intentConnected = new Intent(MainActivity.this,MenuActivity.class);
					//ADD
					intentConnected.putExtra("student", epsiStudents.list.get(i));  
					startActivity(intentConnected);
					
					break;
				}			
			}
			
			if(tmp==false)
				Toast.makeText(this,"Identifiants incorrects", Toast.LENGTH_SHORT).show();
			
			

			
			
		}
		
	}
	
	
	

}
